package logic

import (
	"context"
	"luck/luckrpc/luckrpc"

	"luck/api/internal/svc"
	"luck/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductAddLogic {
	return &ProductAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductAddLogic) ProductAdd(req *types.ProductAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.LuckRpc.ProductAdd(l.ctx, &luckrpc.ProductAddRequest{
		Name:       req.Name,
		Price:      float32(req.Price),
		Stock:      req.Stock,
		Ingredient: req.Ingredient,
		Taste:      req.TasTe,
		Status:     req.Status,
		ImageUrl:   req.ImageUrl,
		CategoryId: req.CategoryId,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "商品添加成功",
		Data:    add,
	}, nil
}
